import { createI18n } from "vue-i18n";
import { queryByList } from "@/api/system/locale";
import type { Language } from "./typing";
import type { ThemeState } from "@/store/theme/typing";
const themeConfig: ThemeState = JSON.parse(
  localStorage.getItem("themeConfig") || "{}"
);
export const defaultLang: Language = themeConfig.system?.locale || "zh-CN";
// 查询国际化
queryByList().then(({ success, result }) => {
  if (success) {
    for (const lang in result) {
      i18n.global.setLocaleMessage(lang, result[lang]);
    }
  }
});
const i18n = createI18n({
  legacy: false,
  missingWarn: false,
  fallbackWarn: false,
  locale: defaultLang,
  messages: {},
});

export default i18n;
